using Microsoft.AspNetCore.Mvc;
using System;
using System.Threading.Tasks;

namespace VOL.demo.Controllers
{
    public partial class PurchaseOrderModelController
    {
        /// <summary>
        /// 分页查询进货订单
        /// </summary>
        /// <param name="pageIndex">页码</param>
        /// <param name="pageSize">每页记录数</param>
        /// <param name="orderCode">进货单号</param>
        /// <param name="status">单据状态</param>
        /// <param name="supplierId">供应商ID</param>
        /// <param name="orderDate">进货日期</param>
        /// <returns>分页结果</returns>
        [HttpGet("GetPageList")]
        public async Task<IActionResult> GetPageList(
            int pageIndex = 1,
            int pageSize = 10,
            string orderCode = null,
            int? status = null,
            long? supplierId = null,
            DateTime? orderDate = null)
        {
            try
            {
                var result = await Service.GetPurchaseOrderPageListAsync(
                    pageIndex, pageSize, orderCode, status, supplierId, orderDate);

                if (result.Status)
                {
                    return Json(result);
                }
                else
                {
                    return Json(new { success = false, message = result.Message });
                }
            }
            catch (Exception ex)
            {
                return Json(new { success = false, message = $"查询失败：{ex.Message}" });
            }
        }
    }
}
